{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "363dec9b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.133783Z",
     "start_time": "2021-05-16T12:23:38.679981Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import gc\n",
    "import warnings\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "from sklearn.metrics import f1_score, roc_auc_score, classification_report\n",
    "from tqdm import tqdm\n",
    "import lightgbm as lgb\n",
    "import os\n",
    "import numpy as np\n",
    "\n",
    "warnings.simplefilter('ignore')\n",
    "pd.set_option('max_columns', None)\n",
    "pd.set_option('max_rows', 500)\n",
    "pd.options.display.max_colwidth = 10000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e875e669",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.138008Z",
     "start_time": "2021-05-16T12:23:39.135721Z"
    }
   },
   "outputs": [],
   "source": [
    "seed = 2021"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a6d5a1ec",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.262043Z",
     "start_time": "2021-05-16T12:23:39.139299Z"
    }
   },
   "outputs": [],
   "source": [
    "df_train = pd.read_csv('raw_data/trainset/recruit_folder.csv')\n",
    "df_test = pd.read_csv('raw_data/testset/recruit_folder.csv')\n",
    "df_test['LABEL'] = np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "befa7493",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.323693Z",
     "start_time": "2021-05-16T12:23:39.263261Z"
    }
   },
   "outputs": [],
   "source": [
    "df_feature = df_train.append(df_test, sort=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a8aa09c4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.421766Z",
     "start_time": "2021-05-16T12:23:39.326074Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.15927573602334874"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_feature['LABEL'].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44bc90d9",
   "metadata": {},
   "source": [
    "# 求职者基本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "679ef3c7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.671430Z",
     "start_time": "2021-05-16T12:23:39.423584Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person = pd.read_csv('raw_data/trainset/person.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "dd20c423",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.680824Z",
     "start_time": "2021-05-16T12:23:39.673259Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person = df_person.drop(columns=['LANGUAGE_REMARK', 'SPECILTY'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8e6144b6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.782299Z",
     "start_time": "2021-05-16T12:23:39.682616Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person.rename(columns={'MAJOR': 'PERSON_MAJOR'}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2d636386",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.878248Z",
     "start_time": "2021-05-16T12:23:39.785474Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PERSON_ID</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>WORK_YEARS</th>\n",
       "      <th>HIGHEST_EDU</th>\n",
       "      <th>PERSON_MAJOR</th>\n",
       "      <th>AGE</th>\n",
       "      <th>LAST_POSITION</th>\n",
       "      <th>LAST_INDUSTRY</th>\n",
       "      <th>CURR_LOC</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>33291</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>大专</td>\n",
       "      <td>计算机应用技术</td>\n",
       "      <td>37</td>\n",
       "      <td>网络管理/信息安全管理</td>\n",
       "      <td>NaN</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2985277</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>大专</td>\n",
       "      <td>计算机应用技术</td>\n",
       "      <td>35</td>\n",
       "      <td>*公关/营销/业务类</td>\n",
       "      <td>文化体育行业</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2982066</td>\n",
       "      <td>女</td>\n",
       "      <td>10</td>\n",
       "      <td>大专</td>\n",
       "      <td>金融学（含保险学）</td>\n",
       "      <td>32</td>\n",
       "      <td>出纳</td>\n",
       "      <td>医药销售行业</td>\n",
       "      <td>南山区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3010866</td>\n",
       "      <td>男</td>\n",
       "      <td>10</td>\n",
       "      <td>中专</td>\n",
       "      <td>物理电子学</td>\n",
       "      <td>34</td>\n",
       "      <td>营销代表/销售顾问</td>\n",
       "      <td>珠宝玉石行业</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>316816964</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>中专</td>\n",
       "      <td>学前教育学</td>\n",
       "      <td>34</td>\n",
       "      <td>小学教育/幼儿教育/保育</td>\n",
       "      <td>行业组织</td>\n",
       "      <td>福田区</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PERSON_ID GENDER  WORK_YEARS HIGHEST_EDU PERSON_MAJOR  AGE LAST_POSITION  \\\n",
       "0      33291      男          15          大专      计算机应用技术   37   网络管理/信息安全管理   \n",
       "1    2985277      男          12          大专      计算机应用技术   35    *公关/营销/业务类   \n",
       "2    2982066      女          10          大专    金融学（含保险学）   32           出纳    \n",
       "3    3010866      男          10          中专        物理电子学   34     营销代表/销售顾问   \n",
       "4  316816964      女          15          中专        学前教育学   34  小学教育/幼儿教育/保育   \n",
       "\n",
       "  LAST_INDUSTRY CURR_LOC  \n",
       "0           NaN      深圳市  \n",
       "1        文化体育行业      深圳市  \n",
       "2        医药销售行业      南山区  \n",
       "3        珠宝玉石行业      深圳市  \n",
       "4          行业组织      福田区  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_person.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "342dc316",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:39.976663Z",
     "start_time": "2021-05-16T12:23:39.880152Z"
    }
   },
   "outputs": [],
   "source": [
    "edu_map = {\n",
    "    '其它': 0,\n",
    "    '中专': 1,\n",
    "    '高中（职高、技校）': 2,\n",
    "    '大专': 3,\n",
    "    '大学本科': 4,\n",
    "    '硕士研究生': 5,\n",
    "    '博士后': 6\n",
    "}\n",
    "\n",
    "df_person['HIGHEST_EDU'] = df_person['HIGHEST_EDU'].map(edu_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "29fd183b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.096700Z",
     "start_time": "2021-05-16T12:23:39.978823Z"
    }
   },
   "outputs": [],
   "source": [
    "def major_clean(x):\n",
    "    if type(x) == float:\n",
    "        return x\n",
    "\n",
    "    x = x.replace('【', '').replace('】', '')\n",
    "    return x\n",
    "\n",
    "\n",
    "df_person['PERSON_MAJOR'] = df_person['PERSON_MAJOR'].apply(major_clean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0a1a327a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.240374Z",
     "start_time": "2021-05-16T12:23:40.098955Z"
    }
   },
   "outputs": [],
   "source": [
    "df_feature = df_feature.merge(df_person, how='left', on='PERSON_ID')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ba05121",
   "metadata": {},
   "source": [
    "# 求职意向"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "47d66efb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.451202Z",
     "start_time": "2021-05-16T12:23:40.241742Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person_cv = pd.read_csv('raw_data/trainset/person_cv.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9110d2b8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.460377Z",
     "start_time": "2021-05-16T12:23:40.452866Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person_cv = df_person_cv.drop(columns=['REMARK', 'SELF_COMMENT'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "840619e0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.554149Z",
     "start_time": "2021-05-16T12:23:40.461464Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person_cv.rename(columns={'LOCATION': 'CV_LOCATION'}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7a1b9961",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.661705Z",
     "start_time": "2021-05-16T12:23:40.556506Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PERSON_ID</th>\n",
       "      <th>POSITION</th>\n",
       "      <th>CV_LOCATION</th>\n",
       "      <th>INDUSTRY</th>\n",
       "      <th>AVAILABLE_IN_DAYS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2985277</td>\n",
       "      <td>导游</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>餐饮旅游娱乐行业</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4736088</td>\n",
       "      <td>*机械类</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3016588</td>\n",
       "      <td>*财务类/审计类</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2981299</td>\n",
       "      <td>*电子/通讯类*</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>能源/光电/电器行业</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2983790</td>\n",
       "      <td>结构技术</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>建筑房地产行业</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PERSON_ID  POSITION CV_LOCATION    INDUSTRY  AVAILABLE_IN_DAYS\n",
       "0    2985277       导游          深圳市    餐饮旅游娱乐行业                NaN\n",
       "1    4736088      *机械类         深圳市         NaN               14.0\n",
       "2    3016588  *财务类/审计类         宝安区         NaN                7.0\n",
       "3    2981299  *电子/通讯类*         深圳市  能源/光电/电器行业                7.0\n",
       "4    2983790      结构技术         深圳市     建筑房地产行业                7.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_person_cv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b5c4bec7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:40.794587Z",
     "start_time": "2021-05-16T12:23:40.663801Z"
    }
   },
   "outputs": [],
   "source": [
    "df_feature = df_feature.merge(df_person_cv, how='left', on='PERSON_ID')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1f863c3",
   "metadata": {},
   "source": [
    "# 工作经历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "30176a2a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.174030Z",
     "start_time": "2021-05-16T12:23:40.797020Z"
    }
   },
   "outputs": [],
   "source": [
    "df_person_job_hist = pd.read_csv('raw_data/trainset/person_job_hist.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5fde0b46",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.181780Z",
     "start_time": "2021-05-16T12:23:41.175544Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PERSON_ID</th>\n",
       "      <th>POSITION</th>\n",
       "      <th>LOCATION</th>\n",
       "      <th>INDUSTRY</th>\n",
       "      <th>ACHIEVEMENT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1281276</td>\n",
       "      <td>行政管理</td>\n",
       "      <td>罗湖区</td>\n",
       "      <td>其它</td>\n",
       "      <td>1.协助总经理处理好日常事务及和外部公共关系；2.负责协助起草总经理各类工作往来文件，并负责有关文件的呈报、催办、归档等管理事宜； 3.协助****公司企业文化、企业战略发展的规划； 4.协助****公司来宾的接待工作；****公司各个项目以及相关日常事务的执行情况，定期跟踪、汇报； 6.兼管行政人事、财务等事务。</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>980158</td>\n",
       "      <td>售前/售后服务</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>本人主要负责万佳,天虹,岁宝,民润等重要客户的品牌分类管理,收集竞争对手信息与反馈,店内执行评估,货架,助销,价格等,建立和维护重点终端客户及kA市场实践经验．</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3016108</td>\n",
       "      <td>培训管理</td>\n",
       "      <td>福田区</td>\n",
       "      <td>信息行业（IT/通讯/互联网）</td>\n",
       "      <td>从事学生管理工作.并负责分校区的学生心理辅导和职业指导工作.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3016108</td>\n",
       "      <td>培训管理</td>\n",
       "      <td>福田区</td>\n",
       "      <td>信息行业（IT/通讯/互联网）</td>\n",
       "      <td>从事心理学的教学工作，并担任学校的心理辅导老师，负责了学校心理咨询中心的组建和日常咨询工作的开展，接受咨询需求****人次以上，获得了良好的社会效益。</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2980989</td>\n",
       "      <td>产品开发</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>电子行业</td>\n",
       "      <td>1.工程师对产品进行设计及开发 2.处理3D图和2D图,同时制作相关的资料(如BOM\\技术文件等)3.修改及更新旧产品结构及性能 4.制作产品的加工工艺及流程5.处理产品的结构及工艺问题</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PERSON_ID POSITION LOCATION         INDUSTRY  \\\n",
       "0    1281276     行政管理      罗湖区               其它   \n",
       "1     980158  售前/售后服务      NaN              NaN   \n",
       "2    3016108     培训管理      福田区  信息行业（IT/通讯/互联网）   \n",
       "3    3016108     培训管理      福田区  信息行业（IT/通讯/互联网）   \n",
       "4    2980989     产品开发      宝安区             电子行业   \n",
       "\n",
       "                                                                                                                                                      ACHIEVEMENT  \n",
       "0  1.协助总经理处理好日常事务及和外部公共关系；2.负责协助起草总经理各类工作往来文件，并负责有关文件的呈报、催办、归档等管理事宜； 3.协助****公司企业文化、企业战略发展的规划； 4.协助****公司来宾的接待工作；****公司各个项目以及相关日常事务的执行情况，定期跟踪、汇报； 6.兼管行政人事、财务等事务。  \n",
       "1                                                                                本人主要负责万佳,天虹,岁宝,民润等重要客户的品牌分类管理,收集竞争对手信息与反馈,店内执行评估,货架,助销,价格等,建立和维护重点终端客户及kA市场实践经验．  \n",
       "2                                                                                                                                 从事学生管理工作.并负责分校区的学生心理辅导和职业指导工作.   \n",
       "3                                                                                     从事心理学的教学工作，并担任学校的心理辅导老师，负责了学校心理咨询中心的组建和日常咨询工作的开展，接受咨询需求****人次以上，获得了良好的社会效益。  \n",
       "4                                                                   1.工程师对产品进行设计及开发 2.处理3D图和2D图,同时制作相关的资料(如BOM\\技术文件等)3.修改及更新旧产品结构及性能 4.制作产品的加工工艺及流程5.处理产品的结构及工艺问题  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_person_job_hist.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "3f006f3d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.322533Z",
     "start_time": "2021-05-16T12:23:41.182967Z"
    }
   },
   "outputs": [],
   "source": [
    "df_tmp = df_person_job_hist.groupby(['PERSON_ID']).size().reset_index()\n",
    "df_tmp.columns = ['PERSON_ID', 'job_hist_cnt']\n",
    "df_feature = df_feature.merge(df_tmp, how='left', on='PERSON_ID')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e932677",
   "metadata": {},
   "source": [
    "# 招聘岗位信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "59ef2fe3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.372522Z",
     "start_time": "2021-05-16T12:23:41.325072Z"
    }
   },
   "outputs": [],
   "source": [
    "df_recruit = pd.read_csv('raw_data/trainset/recruit.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "80d0d040",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.453143Z",
     "start_time": "2021-05-16T12:23:41.374140Z"
    }
   },
   "outputs": [],
   "source": [
    "df_recruit = df_recruit.drop(columns=['DETAIL'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "56dcc592",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.575046Z",
     "start_time": "2021-05-16T12:23:41.455719Z"
    }
   },
   "outputs": [],
   "source": [
    "df_recruit.rename(columns={\n",
    "    'LOCATION': 'RECRUIT_LOCATION',\n",
    "    'MAJOR': 'RECRUIT_MAJOR'\n",
    "},\n",
    "                  inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "87aa7f21",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.666025Z",
     "start_time": "2021-05-16T12:23:41.577680Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RECRUIT_ID</th>\n",
       "      <th>PERSON_TYPE_CODE</th>\n",
       "      <th>PERSON_TYPE</th>\n",
       "      <th>JOB_TITLE</th>\n",
       "      <th>RECRUIT_MAJOR</th>\n",
       "      <th>LOWER_EDU</th>\n",
       "      <th>RECRUIT_LOCATION</th>\n",
       "      <th>WORK_YEARS_RANGE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>135144</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>业务员</td>\n",
       "      <td>NaN</td>\n",
       "      <td>高中（职高、技校）</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>应届毕业生</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>137045</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>电子技术支持工程师</td>\n",
       "      <td>电子信息工程学</td>\n",
       "      <td>中专</td>\n",
       "      <td>龙岗区</td>\n",
       "      <td>0至1年</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>146798</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>仓管</td>\n",
       "      <td>【工商管理】</td>\n",
       "      <td>中专</td>\n",
       "      <td>龙岗区</td>\n",
       "      <td>0至1年</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>436321</td>\n",
       "      <td>2.0</td>\n",
       "      <td>社会无职</td>\n",
       "      <td>销售代表</td>\n",
       "      <td>NaN</td>\n",
       "      <td>中专</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>应届毕业生</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>440725</td>\n",
       "      <td>99.0</td>\n",
       "      <td>不限</td>\n",
       "      <td>造价员</td>\n",
       "      <td>工民建</td>\n",
       "      <td>中专</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>3至5年</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   RECRUIT_ID  PERSON_TYPE_CODE PERSON_TYPE  JOB_TITLE RECRUIT_MAJOR  \\\n",
       "0      135144               NaN         NaN        业务员           NaN   \n",
       "1      137045               NaN         NaN  电子技术支持工程师       电子信息工程学   \n",
       "2      146798               NaN         NaN         仓管        【工商管理】   \n",
       "3      436321               2.0        社会无职       销售代表           NaN   \n",
       "4      440725              99.0          不限        造价员           工民建   \n",
       "\n",
       "   LOWER_EDU RECRUIT_LOCATION WORK_YEARS_RANGE  \n",
       "0  高中（职高、技校）              深圳市            应届毕业生  \n",
       "1         中专              龙岗区             0至1年  \n",
       "2         中专              龙岗区             0至1年  \n",
       "3         中专              深圳市            应届毕业生  \n",
       "4         中专              深圳市             3至5年  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_recruit.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "34f66d69",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.776644Z",
     "start_time": "2021-05-16T12:23:41.668008Z"
    }
   },
   "outputs": [],
   "source": [
    "def major_clean(x):\n",
    "    if type(x) == float:\n",
    "        return x\n",
    "\n",
    "    x = x.replace('【', '').replace('】', '')\n",
    "    return x\n",
    "\n",
    "\n",
    "df_recruit['RECRUIT_MAJOR'] = df_recruit['RECRUIT_MAJOR'].apply(major_clean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "84978123",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.876577Z",
     "start_time": "2021-05-16T12:23:41.783215Z"
    }
   },
   "outputs": [],
   "source": [
    "df_recruit['LOWER_EDU'] = df_recruit['LOWER_EDU'].map(edu_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "225b73dd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:41.987314Z",
     "start_time": "2021-05-16T12:23:41.879972Z"
    }
   },
   "outputs": [],
   "source": [
    "work_year_range_map = {\n",
    "    '应届毕业生': 0,\n",
    "    '0至1年': 1,\n",
    "    '1至2年': 2,\n",
    "    '3至5年': 3,\n",
    "    '5年以上': 4,\n",
    "    '不限': 5\n",
    "}\n",
    "df_recruit['WORK_YEARS_RANGE'] = df_recruit['WORK_YEARS_RANGE'].map(\n",
    "    work_year_range_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "bc0bc96b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:42.141010Z",
     "start_time": "2021-05-16T12:23:41.990028Z"
    }
   },
   "outputs": [],
   "source": [
    "df_feature = df_feature.merge(df_recruit, how='left', on='RECRUIT_ID')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e14c2722",
   "metadata": {},
   "source": [
    "# embedding 特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "75ec829d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:42.239459Z",
     "start_time": "2021-05-16T12:23:42.143734Z"
    }
   },
   "outputs": [],
   "source": [
    "job_title_embeddings = pd.read_pickle('data/embedding/job_title.pkl')\n",
    "df_feature = df_feature.merge(job_title_embeddings, how='left', on='JOB_TITLE')\n",
    "del df_feature['JOB_TITLE']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d40c3c9",
   "metadata": {},
   "source": [
    "# 交叉特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "f278f566",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:43.263824Z",
     "start_time": "2021-05-16T12:23:42.241550Z"
    },
    "code_folding": [
     0
    ]
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [00:00<00:00, 24.45it/s]\n",
      "100%|██████████| 2/2 [00:00<00:00, 26.90it/s]\n",
      "100%|██████████| 2/2 [00:00<00:00, 26.73it/s]\n",
      "100%|██████████| 2/2 [00:00<00:00, 26.60it/s]\n",
      "100%|██████████| 2/2 [00:00<00:00, 26.57it/s]\n",
      "100%|██████████| 2/2 [00:00<00:00, 13.45it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "29"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 简单统计\n",
    "def stat(df, df_merge, group_by, agg):\n",
    "    group = df.groupby(group_by).agg(agg)\n",
    "\n",
    "    columns = []\n",
    "    for on, methods in agg.items():\n",
    "        for method in methods:\n",
    "            columns.append('{}_{}_{}'.format('_'.join(group_by), on, method))\n",
    "    group.columns = columns\n",
    "    group.reset_index(inplace=True)\n",
    "    df_merge = df_merge.merge(group, on=group_by, how='left')\n",
    "\n",
    "    del (group)\n",
    "    gc.collect()\n",
    "\n",
    "    return df_merge\n",
    "\n",
    "\n",
    "def statis_feat(df_know, df_unknow):\n",
    "    for f in tqdm([['CV_LOCATION'], ['RECRUIT_ID']]):\n",
    "        df_unknow = stat(df_know, df_unknow, f, {'LABEL': ['mean']})\n",
    "\n",
    "    return df_unknow\n",
    "\n",
    "\n",
    "# 5折交叉\n",
    "df_train = df_feature[~df_feature['LABEL'].isnull()]\n",
    "df_train = df_train.reset_index(drop=True)\n",
    "df_test = df_feature[df_feature['LABEL'].isnull()]\n",
    "\n",
    "df_stas_feat = None\n",
    "kfold = StratifiedKFold(n_splits=5, random_state=seed, shuffle=True)\n",
    "for train_index, val_index in kfold.split(df_train, df_train['LABEL']):\n",
    "    df_fold_train = df_train.iloc[train_index]\n",
    "    df_fold_val = df_train.iloc[val_index]\n",
    "\n",
    "    df_fold_val = statis_feat(df_fold_train, df_fold_val)\n",
    "    df_stas_feat = pd.concat([df_stas_feat, df_fold_val], axis=0)\n",
    "\n",
    "    del (df_fold_train)\n",
    "    del (df_fold_val)\n",
    "    gc.collect()\n",
    "\n",
    "df_test = statis_feat(df_train, df_test)\n",
    "df_feature = pd.concat([df_stas_feat, df_test], axis=0)\n",
    "\n",
    "del (df_stas_feat)\n",
    "del (df_train)\n",
    "del (df_test)\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "5c8ce1cd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:43.305241Z",
     "start_time": "2021-05-16T12:23:43.264924Z"
    }
   },
   "outputs": [],
   "source": [
    "df_score = pd.read_pickle('data/score.pkl')\n",
    "df_feature = df_feature.merge(df_score, how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "1ebfcbef",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:43.406932Z",
     "start_time": "2021-05-16T12:23:43.307145Z"
    }
   },
   "outputs": [],
   "source": [
    "# count\n",
    "for f in [['PERSON_ID'], ['POSITION']]:\n",
    "    df_feature['{}_cnt'.format(\n",
    "        '_'.join(f))] = df_feature.groupby(f)['PERSON_ID'].transform('count')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "9e530085",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:43.505893Z",
     "start_time": "2021-05-16T12:23:43.408544Z"
    }
   },
   "outputs": [],
   "source": [
    "# nunique\n",
    "for f1, f2 in [['RECRUIT_ID', 'POSITION'], ['RECRUIT_ID', 'PERSON_MAJOR']]:\n",
    "    df_feature[f'{f1}_{f2}_nunique'] = df_feature.groupby(\n",
    "        [f1])[f2].transform('nunique')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "717def0a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:43.674608Z",
     "start_time": "2021-05-16T12:23:43.507149Z"
    }
   },
   "outputs": [],
   "source": [
    "# 连续变量统计\n",
    "for f1, f2 in [['RECRUIT_ID', 'WORK_YEARS']]:\n",
    "    df_temp = df_feature.groupby(f1)[f2].agg({\n",
    "        f'{f1}_{f2}_mean'.format(f): 'mean',\n",
    "        f'{f1}_{f2}_max'.format(f): 'max',\n",
    "        f'{f1}_{f2}_min'.format(f): 'min',\n",
    "        f'{f1}_{f2}_std'.format(f): 'std',\n",
    "    }).reset_index()\n",
    "    df_feature = df_feature.merge(df_temp, how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "6df74756",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:45.979463Z",
     "start_time": "2021-05-16T12:23:43.675930Z"
    }
   },
   "outputs": [],
   "source": [
    "df_feature['CV_RECRUIT_LOCATION_equal'] = df_feature[[\n",
    "    'RECRUIT_LOCATION', 'CV_LOCATION'\n",
    "]].apply(lambda x: x['RECRUIT_LOCATION'] == x['CV_LOCATION'], axis=1)\n",
    "\n",
    "df_feature['LOWER_EDU_HIGHEST_EDU_higher'] = df_feature[[\n",
    "    'LOWER_EDU', 'HIGHEST_EDU'\n",
    "]].apply(lambda x: x['LOWER_EDU'] > x['HIGHEST_EDU'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "31298bca",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:46.028014Z",
     "start_time": "2021-05-16T12:23:45.980695Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RECRUIT_ID</th>\n",
       "      <th>PERSON_ID</th>\n",
       "      <th>LABEL</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>WORK_YEARS</th>\n",
       "      <th>HIGHEST_EDU</th>\n",
       "      <th>PERSON_MAJOR</th>\n",
       "      <th>AGE</th>\n",
       "      <th>LAST_POSITION</th>\n",
       "      <th>LAST_INDUSTRY</th>\n",
       "      <th>CURR_LOC</th>\n",
       "      <th>POSITION</th>\n",
       "      <th>CV_LOCATION</th>\n",
       "      <th>INDUSTRY</th>\n",
       "      <th>AVAILABLE_IN_DAYS</th>\n",
       "      <th>job_hist_cnt</th>\n",
       "      <th>PERSON_TYPE_CODE</th>\n",
       "      <th>PERSON_TYPE</th>\n",
       "      <th>RECRUIT_MAJOR</th>\n",
       "      <th>LOWER_EDU</th>\n",
       "      <th>RECRUIT_LOCATION</th>\n",
       "      <th>WORK_YEARS_RANGE</th>\n",
       "      <th>JOB_TITLE_ernie_emb_0</th>\n",
       "      <th>JOB_TITLE_ernie_emb_1</th>\n",
       "      <th>JOB_TITLE_ernie_emb_2</th>\n",
       "      <th>JOB_TITLE_ernie_emb_3</th>\n",
       "      <th>JOB_TITLE_ernie_emb_4</th>\n",
       "      <th>JOB_TITLE_ernie_emb_5</th>\n",
       "      <th>JOB_TITLE_ernie_emb_6</th>\n",
       "      <th>JOB_TITLE_ernie_emb_7</th>\n",
       "      <th>JOB_TITLE_ernie_emb_8</th>\n",
       "      <th>JOB_TITLE_ernie_emb_9</th>\n",
       "      <th>JOB_TITLE_ernie_emb_10</th>\n",
       "      <th>JOB_TITLE_ernie_emb_11</th>\n",
       "      <th>JOB_TITLE_ernie_emb_12</th>\n",
       "      <th>JOB_TITLE_ernie_emb_13</th>\n",
       "      <th>JOB_TITLE_ernie_emb_14</th>\n",
       "      <th>JOB_TITLE_ernie_emb_15</th>\n",
       "      <th>JOB_TITLE_ernie_emb_16</th>\n",
       "      <th>JOB_TITLE_ernie_emb_17</th>\n",
       "      <th>JOB_TITLE_ernie_emb_18</th>\n",
       "      <th>JOB_TITLE_ernie_emb_19</th>\n",
       "      <th>JOB_TITLE_ernie_emb_20</th>\n",
       "      <th>JOB_TITLE_ernie_emb_21</th>\n",
       "      <th>JOB_TITLE_ernie_emb_22</th>\n",
       "      <th>JOB_TITLE_ernie_emb_23</th>\n",
       "      <th>JOB_TITLE_ernie_emb_24</th>\n",
       "      <th>JOB_TITLE_ernie_emb_25</th>\n",
       "      <th>JOB_TITLE_ernie_emb_26</th>\n",
       "      <th>JOB_TITLE_ernie_emb_27</th>\n",
       "      <th>JOB_TITLE_ernie_emb_28</th>\n",
       "      <th>JOB_TITLE_ernie_emb_29</th>\n",
       "      <th>CV_LOCATION_LABEL_mean</th>\n",
       "      <th>RECRUIT_ID_LABEL_mean</th>\n",
       "      <th>recruit_person_MAJOR_score</th>\n",
       "      <th>PERSON_ID_cnt</th>\n",
       "      <th>POSITION_cnt</th>\n",
       "      <th>RECRUIT_ID_POSITION_nunique</th>\n",
       "      <th>RECRUIT_ID_PERSON_MAJOR_nunique</th>\n",
       "      <th>RECRUIT_ID_WORK_YEARS_mean</th>\n",
       "      <th>RECRUIT_ID_WORK_YEARS_max</th>\n",
       "      <th>RECRUIT_ID_WORK_YEARS_min</th>\n",
       "      <th>RECRUIT_ID_WORK_YEARS_std</th>\n",
       "      <th>CV_RECRUIT_LOCATION_equal</th>\n",
       "      <th>LOWER_EDU_HIGHEST_EDU_higher</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>772899</td>\n",
       "      <td>5413605</td>\n",
       "      <td>0.0</td>\n",
       "      <td>女</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>文秘</td>\n",
       "      <td>29</td>\n",
       "      <td>人力资源管理</td>\n",
       "      <td>通讯行业</td>\n",
       "      <td>广东省</td>\n",
       "      <td>行政管理</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>社会在职</td>\n",
       "      <td>旅游管理</td>\n",
       "      <td>1.0</td>\n",
       "      <td>福田区</td>\n",
       "      <td>2</td>\n",
       "      <td>-0.051337</td>\n",
       "      <td>-0.243886</td>\n",
       "      <td>0.028309</td>\n",
       "      <td>-0.200545</td>\n",
       "      <td>-0.109874</td>\n",
       "      <td>-0.082832</td>\n",
       "      <td>0.341493</td>\n",
       "      <td>-0.113816</td>\n",
       "      <td>-0.216219</td>\n",
       "      <td>-0.110851</td>\n",
       "      <td>-0.133380</td>\n",
       "      <td>-0.183411</td>\n",
       "      <td>-0.079125</td>\n",
       "      <td>-0.434388</td>\n",
       "      <td>0.019965</td>\n",
       "      <td>-0.085903</td>\n",
       "      <td>-0.015218</td>\n",
       "      <td>-0.248044</td>\n",
       "      <td>0.247061</td>\n",
       "      <td>-0.285383</td>\n",
       "      <td>0.084865</td>\n",
       "      <td>0.000443</td>\n",
       "      <td>0.066399</td>\n",
       "      <td>-0.007481</td>\n",
       "      <td>0.205345</td>\n",
       "      <td>0.141893</td>\n",
       "      <td>0.189973</td>\n",
       "      <td>-0.235695</td>\n",
       "      <td>-0.182161</td>\n",
       "      <td>0.179240</td>\n",
       "      <td>0.147827</td>\n",
       "      <td>0.024390</td>\n",
       "      <td>0.056579</td>\n",
       "      <td>2</td>\n",
       "      <td>2240.0</td>\n",
       "      <td>121</td>\n",
       "      <td>124</td>\n",
       "      <td>6.532100</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>5.060721</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>813938</td>\n",
       "      <td>1391289</td>\n",
       "      <td>1.0</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>3.0</td>\n",
       "      <td>计算机科学与技术</td>\n",
       "      <td>34</td>\n",
       "      <td>网络管理/信息安全管理</td>\n",
       "      <td>NaN</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>项目实施/顾问</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>信息行业（IT/通讯/互联网）</td>\n",
       "      <td>14.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>软件工程</td>\n",
       "      <td>3.0</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>0</td>\n",
       "      <td>0.234713</td>\n",
       "      <td>-0.123183</td>\n",
       "      <td>-0.120129</td>\n",
       "      <td>0.181092</td>\n",
       "      <td>0.104147</td>\n",
       "      <td>0.089959</td>\n",
       "      <td>0.020083</td>\n",
       "      <td>-0.006046</td>\n",
       "      <td>0.109227</td>\n",
       "      <td>-0.333411</td>\n",
       "      <td>-0.011447</td>\n",
       "      <td>0.298391</td>\n",
       "      <td>0.104235</td>\n",
       "      <td>-0.130547</td>\n",
       "      <td>0.074952</td>\n",
       "      <td>-0.129922</td>\n",
       "      <td>-0.189609</td>\n",
       "      <td>0.311192</td>\n",
       "      <td>-0.101285</td>\n",
       "      <td>-0.053433</td>\n",
       "      <td>-0.051312</td>\n",
       "      <td>0.271554</td>\n",
       "      <td>-0.015772</td>\n",
       "      <td>0.075361</td>\n",
       "      <td>-0.368809</td>\n",
       "      <td>-0.015872</td>\n",
       "      <td>-0.207454</td>\n",
       "      <td>-0.277825</td>\n",
       "      <td>0.273316</td>\n",
       "      <td>0.202631</td>\n",
       "      <td>0.147827</td>\n",
       "      <td>0.695652</td>\n",
       "      <td>0.182027</td>\n",
       "      <td>1</td>\n",
       "      <td>322.0</td>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "      <td>7.459770</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>5.909796</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>795526</td>\n",
       "      <td>6196384</td>\n",
       "      <td>0.0</td>\n",
       "      <td>女</td>\n",
       "      <td>6</td>\n",
       "      <td>3.0</td>\n",
       "      <td>文秘</td>\n",
       "      <td>29</td>\n",
       "      <td>客户服务</td>\n",
       "      <td>NaN</td>\n",
       "      <td>罗湖区</td>\n",
       "      <td>国际贸易/涉外业务</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>商业零售行业</td>\n",
       "      <td>14.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>福田区</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.315937</td>\n",
       "      <td>-0.185878</td>\n",
       "      <td>-0.069693</td>\n",
       "      <td>-0.238269</td>\n",
       "      <td>-0.061867</td>\n",
       "      <td>-0.047715</td>\n",
       "      <td>0.443191</td>\n",
       "      <td>0.271410</td>\n",
       "      <td>-0.099232</td>\n",
       "      <td>0.248548</td>\n",
       "      <td>-0.201732</td>\n",
       "      <td>-0.266306</td>\n",
       "      <td>0.231007</td>\n",
       "      <td>0.085372</td>\n",
       "      <td>0.187326</td>\n",
       "      <td>0.144522</td>\n",
       "      <td>-0.300614</td>\n",
       "      <td>0.016540</td>\n",
       "      <td>0.118367</td>\n",
       "      <td>-0.107304</td>\n",
       "      <td>0.102943</td>\n",
       "      <td>0.069849</td>\n",
       "      <td>0.012187</td>\n",
       "      <td>-0.070502</td>\n",
       "      <td>0.050517</td>\n",
       "      <td>-0.063172</td>\n",
       "      <td>-0.141544</td>\n",
       "      <td>0.068182</td>\n",
       "      <td>-0.214175</td>\n",
       "      <td>0.118705</td>\n",
       "      <td>0.147827</td>\n",
       "      <td>0.005435</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>5</td>\n",
       "      <td>6018.0</td>\n",
       "      <td>88</td>\n",
       "      <td>97</td>\n",
       "      <td>6.677188</td>\n",
       "      <td>22</td>\n",
       "      <td>0</td>\n",
       "      <td>4.694759</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>781773</td>\n",
       "      <td>1340058</td>\n",
       "      <td>0.0</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>3.0</td>\n",
       "      <td>机械制造及其自动化</td>\n",
       "      <td>35</td>\n",
       "      <td>电子/数码产品开发</td>\n",
       "      <td>NaN</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>结构技术</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>社会在职</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>龙岗区</td>\n",
       "      <td>3</td>\n",
       "      <td>0.033851</td>\n",
       "      <td>-0.038578</td>\n",
       "      <td>-0.117304</td>\n",
       "      <td>0.086912</td>\n",
       "      <td>-0.594854</td>\n",
       "      <td>-0.009151</td>\n",
       "      <td>-0.142161</td>\n",
       "      <td>-0.198133</td>\n",
       "      <td>0.272518</td>\n",
       "      <td>0.107589</td>\n",
       "      <td>-0.217581</td>\n",
       "      <td>-0.304624</td>\n",
       "      <td>0.245591</td>\n",
       "      <td>-0.072930</td>\n",
       "      <td>0.260233</td>\n",
       "      <td>-0.204289</td>\n",
       "      <td>0.010460</td>\n",
       "      <td>-0.092746</td>\n",
       "      <td>-0.029742</td>\n",
       "      <td>0.149046</td>\n",
       "      <td>-0.185682</td>\n",
       "      <td>0.045448</td>\n",
       "      <td>0.212247</td>\n",
       "      <td>-0.001426</td>\n",
       "      <td>0.112673</td>\n",
       "      <td>-0.117515</td>\n",
       "      <td>-0.078132</td>\n",
       "      <td>0.077578</td>\n",
       "      <td>-0.093877</td>\n",
       "      <td>0.027175</td>\n",
       "      <td>0.147827</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>207.0</td>\n",
       "      <td>51</td>\n",
       "      <td>38</td>\n",
       "      <td>9.671512</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>5.932045</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>820496</td>\n",
       "      <td>5869866</td>\n",
       "      <td>1.0</td>\n",
       "      <td>女</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "      <td>电子商务</td>\n",
       "      <td>31</td>\n",
       "      <td>行政管理</td>\n",
       "      <td>互联网行业</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>行政管理</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>社会在职</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>福田区</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.076386</td>\n",
       "      <td>-0.224421</td>\n",
       "      <td>0.067912</td>\n",
       "      <td>-0.017263</td>\n",
       "      <td>0.226272</td>\n",
       "      <td>-0.289024</td>\n",
       "      <td>-0.402977</td>\n",
       "      <td>-0.146860</td>\n",
       "      <td>0.118392</td>\n",
       "      <td>-0.006297</td>\n",
       "      <td>0.259484</td>\n",
       "      <td>0.083771</td>\n",
       "      <td>0.030424</td>\n",
       "      <td>-0.125321</td>\n",
       "      <td>-0.283175</td>\n",
       "      <td>-0.134899</td>\n",
       "      <td>0.037033</td>\n",
       "      <td>-0.040271</td>\n",
       "      <td>-0.069357</td>\n",
       "      <td>0.123851</td>\n",
       "      <td>0.091143</td>\n",
       "      <td>-0.050242</td>\n",
       "      <td>0.068554</td>\n",
       "      <td>-0.433342</td>\n",
       "      <td>0.399648</td>\n",
       "      <td>-0.135726</td>\n",
       "      <td>0.071339</td>\n",
       "      <td>-0.050783</td>\n",
       "      <td>-0.054708</td>\n",
       "      <td>-0.038917</td>\n",
       "      <td>0.296959</td>\n",
       "      <td>0.600000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>2</td>\n",
       "      <td>2240.0</td>\n",
       "      <td>20</td>\n",
       "      <td>14</td>\n",
       "      <td>9.641026</td>\n",
       "      <td>20</td>\n",
       "      <td>0</td>\n",
       "      <td>4.498463</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   RECRUIT_ID  PERSON_ID  LABEL GENDER  WORK_YEARS  HIGHEST_EDU PERSON_MAJOR  \\\n",
       "0      772899    5413605    0.0      女           0          3.0           文秘   \n",
       "1      813938    1391289    1.0      男          12          3.0     计算机科学与技术   \n",
       "2      795526    6196384    0.0      女           6          3.0           文秘   \n",
       "3      781773    1340058    0.0      男          12          3.0    机械制造及其自动化   \n",
       "4      820496    5869866    1.0      女           9          4.0         电子商务   \n",
       "\n",
       "   AGE LAST_POSITION LAST_INDUSTRY CURR_LOC   POSITION CV_LOCATION  \\\n",
       "0   29        人力资源管理          通讯行业      广东省       行政管理         深圳市   \n",
       "1   34   网络管理/信息安全管理           NaN      深圳市    项目实施/顾问         深圳市   \n",
       "2   29          客户服务           NaN      罗湖区  国际贸易/涉外业务         深圳市   \n",
       "3   35     电子/数码产品开发           NaN      宝安区       结构技术         深圳市   \n",
       "4   31          行政管理         互联网行业      宝安区       行政管理         宝安区   \n",
       "\n",
       "          INDUSTRY  AVAILABLE_IN_DAYS  job_hist_cnt  PERSON_TYPE_CODE  \\\n",
       "0              NaN               30.0           2.0               1.0   \n",
       "1  信息行业（IT/通讯/互联网）               14.0           4.0               NaN   \n",
       "2           商业零售行业               14.0           1.0               NaN   \n",
       "3              NaN               30.0           3.0               1.0   \n",
       "4              NaN                7.0           4.0               1.0   \n",
       "\n",
       "  PERSON_TYPE RECRUIT_MAJOR  LOWER_EDU RECRUIT_LOCATION  WORK_YEARS_RANGE  \\\n",
       "0        社会在职          旅游管理        1.0              福田区                 2   \n",
       "1         NaN          软件工程        3.0              深圳市                 0   \n",
       "2         NaN           NaN        1.0              福田区                 1   \n",
       "3        社会在职           NaN        3.0              龙岗区                 3   \n",
       "4        社会在职           NaN        2.0              福田区                 1   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_0  JOB_TITLE_ernie_emb_1  JOB_TITLE_ernie_emb_2  \\\n",
       "0              -0.051337              -0.243886               0.028309   \n",
       "1               0.234713              -0.123183              -0.120129   \n",
       "2              -0.315937              -0.185878              -0.069693   \n",
       "3               0.033851              -0.038578              -0.117304   \n",
       "4              -0.076386              -0.224421               0.067912   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_3  JOB_TITLE_ernie_emb_4  JOB_TITLE_ernie_emb_5  \\\n",
       "0              -0.200545              -0.109874              -0.082832   \n",
       "1               0.181092               0.104147               0.089959   \n",
       "2              -0.238269              -0.061867              -0.047715   \n",
       "3               0.086912              -0.594854              -0.009151   \n",
       "4              -0.017263               0.226272              -0.289024   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_6  JOB_TITLE_ernie_emb_7  JOB_TITLE_ernie_emb_8  \\\n",
       "0               0.341493              -0.113816              -0.216219   \n",
       "1               0.020083              -0.006046               0.109227   \n",
       "2               0.443191               0.271410              -0.099232   \n",
       "3              -0.142161              -0.198133               0.272518   \n",
       "4              -0.402977              -0.146860               0.118392   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_9  JOB_TITLE_ernie_emb_10  JOB_TITLE_ernie_emb_11  \\\n",
       "0              -0.110851               -0.133380               -0.183411   \n",
       "1              -0.333411               -0.011447                0.298391   \n",
       "2               0.248548               -0.201732               -0.266306   \n",
       "3               0.107589               -0.217581               -0.304624   \n",
       "4              -0.006297                0.259484                0.083771   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_12  JOB_TITLE_ernie_emb_13  JOB_TITLE_ernie_emb_14  \\\n",
       "0               -0.079125               -0.434388                0.019965   \n",
       "1                0.104235               -0.130547                0.074952   \n",
       "2                0.231007                0.085372                0.187326   \n",
       "3                0.245591               -0.072930                0.260233   \n",
       "4                0.030424               -0.125321               -0.283175   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_15  JOB_TITLE_ernie_emb_16  JOB_TITLE_ernie_emb_17  \\\n",
       "0               -0.085903               -0.015218               -0.248044   \n",
       "1               -0.129922               -0.189609                0.311192   \n",
       "2                0.144522               -0.300614                0.016540   \n",
       "3               -0.204289                0.010460               -0.092746   \n",
       "4               -0.134899                0.037033               -0.040271   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_18  JOB_TITLE_ernie_emb_19  JOB_TITLE_ernie_emb_20  \\\n",
       "0                0.247061               -0.285383                0.084865   \n",
       "1               -0.101285               -0.053433               -0.051312   \n",
       "2                0.118367               -0.107304                0.102943   \n",
       "3               -0.029742                0.149046               -0.185682   \n",
       "4               -0.069357                0.123851                0.091143   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_21  JOB_TITLE_ernie_emb_22  JOB_TITLE_ernie_emb_23  \\\n",
       "0                0.000443                0.066399               -0.007481   \n",
       "1                0.271554               -0.015772                0.075361   \n",
       "2                0.069849                0.012187               -0.070502   \n",
       "3                0.045448                0.212247               -0.001426   \n",
       "4               -0.050242                0.068554               -0.433342   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_24  JOB_TITLE_ernie_emb_25  JOB_TITLE_ernie_emb_26  \\\n",
       "0                0.205345                0.141893                0.189973   \n",
       "1               -0.368809               -0.015872               -0.207454   \n",
       "2                0.050517               -0.063172               -0.141544   \n",
       "3                0.112673               -0.117515               -0.078132   \n",
       "4                0.399648               -0.135726                0.071339   \n",
       "\n",
       "   JOB_TITLE_ernie_emb_27  JOB_TITLE_ernie_emb_28  JOB_TITLE_ernie_emb_29  \\\n",
       "0               -0.235695               -0.182161                0.179240   \n",
       "1               -0.277825                0.273316                0.202631   \n",
       "2                0.068182               -0.214175                0.118705   \n",
       "3                0.077578               -0.093877                0.027175   \n",
       "4               -0.050783               -0.054708               -0.038917   \n",
       "\n",
       "   CV_LOCATION_LABEL_mean  RECRUIT_ID_LABEL_mean  recruit_person_MAJOR_score  \\\n",
       "0                0.147827               0.024390                    0.056579   \n",
       "1                0.147827               0.695652                    0.182027   \n",
       "2                0.147827               0.005435                   -1.000000   \n",
       "3                0.147827               0.000000                   -1.000000   \n",
       "4                0.296959               0.600000                   -1.000000   \n",
       "\n",
       "   PERSON_ID_cnt  POSITION_cnt  RECRUIT_ID_POSITION_nunique  \\\n",
       "0              2        2240.0                          121   \n",
       "1              1         322.0                           23   \n",
       "2              5        6018.0                           88   \n",
       "3              1         207.0                           51   \n",
       "4              2        2240.0                           20   \n",
       "\n",
       "   RECRUIT_ID_PERSON_MAJOR_nunique  RECRUIT_ID_WORK_YEARS_mean  \\\n",
       "0                              124                    6.532100   \n",
       "1                               11                    7.459770   \n",
       "2                               97                    6.677188   \n",
       "3                               38                    9.671512   \n",
       "4                               14                    9.641026   \n",
       "\n",
       "   RECRUIT_ID_WORK_YEARS_max  RECRUIT_ID_WORK_YEARS_min  \\\n",
       "0                         28                          0   \n",
       "1                         24                          0   \n",
       "2                         22                          0   \n",
       "3                         35                          0   \n",
       "4                         20                          0   \n",
       "\n",
       "   RECRUIT_ID_WORK_YEARS_std  CV_RECRUIT_LOCATION_equal  \\\n",
       "0                   5.060721                      False   \n",
       "1                   5.909796                       True   \n",
       "2                   4.694759                      False   \n",
       "3                   5.932045                      False   \n",
       "4                   4.498463                      False   \n",
       "\n",
       "   LOWER_EDU_HIGHEST_EDU_higher  \n",
       "0                         False  \n",
       "1                         False  \n",
       "2                         False  \n",
       "3                         False  \n",
       "4                         False  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_feature.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b026cea7",
   "metadata": {},
   "source": [
    "# 建模"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "beca8f2d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:46.640320Z",
     "start_time": "2021-05-16T12:23:46.029366Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GENDER\n",
      "PERSON_MAJOR\n",
      "LAST_POSITION\n",
      "LAST_INDUSTRY\n",
      "CURR_LOC\n",
      "POSITION\n",
      "CV_LOCATION\n",
      "INDUSTRY\n",
      "PERSON_TYPE\n",
      "RECRUIT_MAJOR\n",
      "RECRUIT_LOCATION\n"
     ]
    }
   ],
   "source": [
    "for f in df_feature.select_dtypes('object'):\n",
    "    le = LabelEncoder()\n",
    "    print(f)\n",
    "    df_feature[f] = le.fit_transform(df_feature[f].astype('str'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "c1b7cdc4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:46.662176Z",
     "start_time": "2021-05-16T12:23:46.641447Z"
    }
   },
   "outputs": [],
   "source": [
    "df_train = df_feature[df_feature['LABEL'].notnull()]\n",
    "df_test = df_feature[df_feature['LABEL'].isnull()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "4247736b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:46.730940Z",
     "start_time": "2021-05-16T12:23:46.663559Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((35291, 65), (70774, 65))"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_train.shape, df_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c3a8f022",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.260019Z",
     "start_time": "2021-05-16T12:23:46.733057Z"
    },
    "code_folding": [
     8,
     20
    ],
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Fold_1 Training ================================\n",
      "\n",
      "[LightGBM] [Warning] feature_fraction is set=0.8, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.8\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's auc: 0.984237\n",
      "Early stopping, best iteration is:\n",
      "[93]\tvalid's auc: 0.984317\n",
      "\n",
      "Fold_2 Training ================================\n",
      "\n",
      "[LightGBM] [Warning] feature_fraction is set=0.8, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.8\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's auc: 0.980044\n",
      "[200]\tvalid's auc: 0.979965\n",
      "Early stopping, best iteration is:\n",
      "[135]\tvalid's auc: 0.980294\n",
      "\n",
      "Fold_3 Training ================================\n",
      "\n",
      "[LightGBM] [Warning] feature_fraction is set=0.8, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.8\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's auc: 0.979141\n",
      "[200]\tvalid's auc: 0.979322\n",
      "Early stopping, best iteration is:\n",
      "[140]\tvalid's auc: 0.97951\n",
      "\n",
      "Fold_4 Training ================================\n",
      "\n",
      "[LightGBM] [Warning] feature_fraction is set=0.8, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.8\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's auc: 0.982674\n",
      "[200]\tvalid's auc: 0.982694\n",
      "Early stopping, best iteration is:\n",
      "[116]\tvalid's auc: 0.982874\n",
      "\n",
      "Fold_5 Training ================================\n",
      "\n",
      "[LightGBM] [Warning] feature_fraction is set=0.8, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.8\n",
      "Training until validation scores don't improve for 100 rounds\n",
      "[100]\tvalid's auc: 0.982222\n",
      "[200]\tvalid's auc: 0.981732\n",
      "Early stopping, best iteration is:\n",
      "[142]\tvalid's auc: 0.982444\n"
     ]
    }
   ],
   "source": [
    "ycol = 'LABEL'\n",
    "feature_names = list(filter(lambda x: x not in [ycol], df_train.columns))\n",
    "\n",
    "oof = []\n",
    "prediction = df_test[['RECRUIT_ID', 'PERSON_ID']]\n",
    "prediction['pred'] = 0\n",
    "df_importance_list = []\n",
    "\n",
    "model = lgb.LGBMClassifier(num_leaves=64,\n",
    "                           max_depth=10,\n",
    "                           learning_rate=0.1,\n",
    "                           n_estimators=1000000,\n",
    "                           subsample=0.8,\n",
    "                           feature_fraction=0.8,\n",
    "                           reg_alpha=0.5,\n",
    "                           reg_lambda=0.5,\n",
    "                           random_state=seed,\n",
    "                           metric='auc')\n",
    "\n",
    "kfold = StratifiedKFold(n_splits=5, random_state=seed, shuffle=True)\n",
    "for fold_id, (trn_idx, val_idx) in enumerate(\n",
    "        kfold.split(df_train[feature_names], df_train[ycol])):\n",
    "    X_train = df_train.iloc[trn_idx][feature_names]\n",
    "    Y_train = df_train.iloc[trn_idx][ycol]\n",
    "\n",
    "    X_val = df_train.iloc[val_idx][feature_names]\n",
    "    Y_val = df_train.iloc[val_idx][ycol]\n",
    "\n",
    "    print('\\nFold_{} Training ================================\\n'.format(\n",
    "        fold_id + 1))\n",
    "\n",
    "    lgb_model = model.fit(X_train,\n",
    "                          Y_train,\n",
    "                          eval_names=['valid'],\n",
    "                          eval_set=[(X_val, Y_val)],\n",
    "                          verbose=100,\n",
    "                          eval_metric='auc',\n",
    "                          early_stopping_rounds=100)\n",
    "\n",
    "    pred_val = lgb_model.predict_proba(X_val)\n",
    "    df_oof = df_train.iloc[val_idx][['RECRUIT_ID', 'PERSON_ID', ycol]].copy()\n",
    "    df_oof['pred'] = pred_val[:, 1]\n",
    "    oof.append(df_oof)\n",
    "\n",
    "    pred_test = lgb_model.predict_proba(df_test[feature_names])\n",
    "    prediction['pred'] += pred_test[:, 1] / kfold.n_splits\n",
    "\n",
    "    df_importance = pd.DataFrame({\n",
    "        'column': feature_names,\n",
    "        'importance': model.feature_importances_,\n",
    "    })\n",
    "    df_importance_list.append(df_importance)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "d2a5355d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.271880Z",
     "start_time": "2021-05-16T12:23:53.261369Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>column</th>\n",
       "      <th>importance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>PERSON_ID</td>\n",
       "      <td>627.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>RECRUIT_ID_LABEL_mean</td>\n",
       "      <td>478.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PERSON_MAJOR</td>\n",
       "      <td>311.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>POSITION</td>\n",
       "      <td>294.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>POSITION_cnt</td>\n",
       "      <td>293.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>RECRUIT_ID</td>\n",
       "      <td>280.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>PERSON_ID_cnt</td>\n",
       "      <td>268.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>WORK_YEARS</td>\n",
       "      <td>253.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>AGE</td>\n",
       "      <td>235.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>LAST_POSITION</td>\n",
       "      <td>216.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>LAST_INDUSTRY</td>\n",
       "      <td>162.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>RECRUIT_ID_POSITION_nunique</td>\n",
       "      <td>156.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>RECRUIT_ID_WORK_YEARS_mean</td>\n",
       "      <td>156.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>RECRUIT_ID_WORK_YEARS_std</td>\n",
       "      <td>156.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>INDUSTRY</td>\n",
       "      <td>155.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>job_hist_cnt</td>\n",
       "      <td>151.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>CV_LOCATION_LABEL_mean</td>\n",
       "      <td>148.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>RECRUIT_ID_PERSON_MAJOR_nunique</td>\n",
       "      <td>122.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>JOB_TITLE_ernie_emb_19</td>\n",
       "      <td>112.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>CURR_LOC</td>\n",
       "      <td>108.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>JOB_TITLE_ernie_emb_22</td>\n",
       "      <td>103.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>JOB_TITLE_ernie_emb_10</td>\n",
       "      <td>100.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>JOB_TITLE_ernie_emb_12</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>JOB_TITLE_ernie_emb_24</td>\n",
       "      <td>96.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>JOB_TITLE_ernie_emb_9</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>JOB_TITLE_ernie_emb_20</td>\n",
       "      <td>94.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>GENDER</td>\n",
       "      <td>94.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>JOB_TITLE_ernie_emb_15</td>\n",
       "      <td>94.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>JOB_TITLE_ernie_emb_29</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>JOB_TITLE_ernie_emb_16</td>\n",
       "      <td>93.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>JOB_TITLE_ernie_emb_8</td>\n",
       "      <td>92.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>JOB_TITLE_ernie_emb_28</td>\n",
       "      <td>91.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>JOB_TITLE_ernie_emb_25</td>\n",
       "      <td>88.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>JOB_TITLE_ernie_emb_14</td>\n",
       "      <td>88.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>JOB_TITLE_ernie_emb_13</td>\n",
       "      <td>87.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>JOB_TITLE_ernie_emb_17</td>\n",
       "      <td>86.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>JOB_TITLE_ernie_emb_6</td>\n",
       "      <td>85.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>RECRUIT_ID_WORK_YEARS_max</td>\n",
       "      <td>85.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>JOB_TITLE_ernie_emb_23</td>\n",
       "      <td>84.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>JOB_TITLE_ernie_emb_5</td>\n",
       "      <td>84.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>JOB_TITLE_ernie_emb_11</td>\n",
       "      <td>83.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>recruit_person_MAJOR_score</td>\n",
       "      <td>83.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>JOB_TITLE_ernie_emb_27</td>\n",
       "      <td>81.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>JOB_TITLE_ernie_emb_7</td>\n",
       "      <td>80.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>JOB_TITLE_ernie_emb_1</td>\n",
       "      <td>79.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>JOB_TITLE_ernie_emb_3</td>\n",
       "      <td>77.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>JOB_TITLE_ernie_emb_21</td>\n",
       "      <td>75.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>JOB_TITLE_ernie_emb_0</td>\n",
       "      <td>71.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>JOB_TITLE_ernie_emb_4</td>\n",
       "      <td>70.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>JOB_TITLE_ernie_emb_26</td>\n",
       "      <td>70.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>JOB_TITLE_ernie_emb_18</td>\n",
       "      <td>69.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>HIGHEST_EDU</td>\n",
       "      <td>69.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>JOB_TITLE_ernie_emb_2</td>\n",
       "      <td>66.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>AVAILABLE_IN_DAYS</td>\n",
       "      <td>63.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>LOWER_EDU</td>\n",
       "      <td>62.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>PERSON_TYPE_CODE</td>\n",
       "      <td>50.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>RECRUIT_LOCATION</td>\n",
       "      <td>46.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>RECRUIT_MAJOR</td>\n",
       "      <td>45.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>WORK_YEARS_RANGE</td>\n",
       "      <td>32.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>LOWER_EDU_HIGHEST_EDU_higher</td>\n",
       "      <td>29.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>CV_LOCATION</td>\n",
       "      <td>24.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>CV_RECRUIT_LOCATION_equal</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>PERSON_TYPE</td>\n",
       "      <td>10.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>RECRUIT_ID_WORK_YEARS_min</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             column  importance\n",
       "0                         PERSON_ID       627.8\n",
       "1             RECRUIT_ID_LABEL_mean       478.0\n",
       "2                      PERSON_MAJOR       311.6\n",
       "3                          POSITION       294.2\n",
       "4                      POSITION_cnt       293.2\n",
       "5                        RECRUIT_ID       280.2\n",
       "6                     PERSON_ID_cnt       268.2\n",
       "7                        WORK_YEARS       253.0\n",
       "8                               AGE       235.0\n",
       "9                     LAST_POSITION       216.2\n",
       "10                    LAST_INDUSTRY       162.0\n",
       "11      RECRUIT_ID_POSITION_nunique       156.6\n",
       "12       RECRUIT_ID_WORK_YEARS_mean       156.2\n",
       "13        RECRUIT_ID_WORK_YEARS_std       156.2\n",
       "14                         INDUSTRY       155.6\n",
       "15                     job_hist_cnt       151.4\n",
       "16           CV_LOCATION_LABEL_mean       148.0\n",
       "17  RECRUIT_ID_PERSON_MAJOR_nunique       122.0\n",
       "18           JOB_TITLE_ernie_emb_19       112.6\n",
       "19                         CURR_LOC       108.6\n",
       "20           JOB_TITLE_ernie_emb_22       103.4\n",
       "21           JOB_TITLE_ernie_emb_10       100.2\n",
       "22           JOB_TITLE_ernie_emb_12        99.0\n",
       "23           JOB_TITLE_ernie_emb_24        96.8\n",
       "24            JOB_TITLE_ernie_emb_9        95.0\n",
       "25           JOB_TITLE_ernie_emb_20        94.6\n",
       "26                           GENDER        94.6\n",
       "27           JOB_TITLE_ernie_emb_15        94.2\n",
       "28           JOB_TITLE_ernie_emb_29        94.0\n",
       "29           JOB_TITLE_ernie_emb_16        93.4\n",
       "30            JOB_TITLE_ernie_emb_8        92.2\n",
       "31           JOB_TITLE_ernie_emb_28        91.6\n",
       "32           JOB_TITLE_ernie_emb_25        88.8\n",
       "33           JOB_TITLE_ernie_emb_14        88.4\n",
       "34           JOB_TITLE_ernie_emb_13        87.6\n",
       "35           JOB_TITLE_ernie_emb_17        86.6\n",
       "36            JOB_TITLE_ernie_emb_6        85.8\n",
       "37        RECRUIT_ID_WORK_YEARS_max        85.6\n",
       "38           JOB_TITLE_ernie_emb_23        84.8\n",
       "39            JOB_TITLE_ernie_emb_5        84.6\n",
       "40           JOB_TITLE_ernie_emb_11        83.4\n",
       "41       recruit_person_MAJOR_score        83.2\n",
       "42           JOB_TITLE_ernie_emb_27        81.0\n",
       "43            JOB_TITLE_ernie_emb_7        80.8\n",
       "44            JOB_TITLE_ernie_emb_1        79.0\n",
       "45            JOB_TITLE_ernie_emb_3        77.6\n",
       "46           JOB_TITLE_ernie_emb_21        75.2\n",
       "47            JOB_TITLE_ernie_emb_0        71.4\n",
       "48            JOB_TITLE_ernie_emb_4        70.8\n",
       "49           JOB_TITLE_ernie_emb_26        70.4\n",
       "50           JOB_TITLE_ernie_emb_18        69.6\n",
       "51                      HIGHEST_EDU        69.2\n",
       "52            JOB_TITLE_ernie_emb_2        66.8\n",
       "53                AVAILABLE_IN_DAYS        63.0\n",
       "54                        LOWER_EDU        62.6\n",
       "55                 PERSON_TYPE_CODE        50.2\n",
       "56                 RECRUIT_LOCATION        46.6\n",
       "57                    RECRUIT_MAJOR        45.6\n",
       "58                 WORK_YEARS_RANGE        32.4\n",
       "59     LOWER_EDU_HIGHEST_EDU_higher        29.6\n",
       "60                      CV_LOCATION        24.4\n",
       "61        CV_RECRUIT_LOCATION_equal        12.0\n",
       "62                      PERSON_TYPE        10.6\n",
       "63        RECRUIT_ID_WORK_YEARS_min         1.8"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_importance = pd.concat(df_importance_list)\n",
    "df_importance = df_importance.groupby([\n",
    "    'column'\n",
    "])['importance'].agg('mean').sort_values(ascending=False).reset_index()\n",
    "df_importance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "9dfc0e97",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.408469Z",
     "start_time": "2021-05-16T12:23:53.272645Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.8652822151224707, 0.981616311118922)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_oof = pd.concat(oof)\n",
    "df_oof.sort_values(['pred'], inplace=True, ascending=False)\n",
    "df_oof.reset_index(drop=True, inplace=True)\n",
    "df_oof['pred_label'] = 0\n",
    "df_oof.loc[:int(0.16 * len(df_oof)), 'pred_label'] = 1\n",
    "f1 = f1_score(df_oof[ycol], df_oof['pred_label'])\n",
    "auc = roc_auc_score(df_oof[ycol], df_oof['pred'])\n",
    "f1, auc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "46302290",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.483185Z",
     "start_time": "2021-05-16T12:23:53.409362Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             precision    recall  f1-score   support\n",
      "\n",
      "        0.0       0.97      0.97      0.97     29670\n",
      "        1.0       0.86      0.87      0.87      5621\n",
      "\n",
      "avg / total       0.96      0.96      0.96     35291\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(classification_report(df_oof[ycol], df_oof['pred_label']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "33083437",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.581047Z",
     "start_time": "2021-05-16T12:23:53.485422Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    59450\n",
       "1    11324\n",
       "Name: LABEL, dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prediction.sort_values(['pred'], inplace=True, ascending=False)\n",
    "prediction.reset_index(drop=True, inplace=True)\n",
    "prediction['LABEL'] = 0\n",
    "prediction.loc[:int(0.16 * len(prediction)), 'LABEL'] = 1\n",
    "prediction['LABEL'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "5f67ecf2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.653232Z",
     "start_time": "2021-05-16T12:23:53.582347Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RECRUIT_ID</th>\n",
       "      <th>PERSON_ID</th>\n",
       "      <th>LABEL</th>\n",
       "      <th>pred</th>\n",
       "      <th>pred_label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>42559662</td>\n",
       "      <td>320003954</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999951</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>42559662</td>\n",
       "      <td>320338907</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999949</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>42939022</td>\n",
       "      <td>317516901</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999948</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>43236688</td>\n",
       "      <td>317282943</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999946</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>43922680</td>\n",
       "      <td>319489936</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999943</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>43668705</td>\n",
       "      <td>320540944</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999943</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>43534698</td>\n",
       "      <td>317244952</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999942</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>44254655</td>\n",
       "      <td>320042903</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999942</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>43897745</td>\n",
       "      <td>319677903</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999941</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>42989690</td>\n",
       "      <td>317729913</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999941</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>43892655</td>\n",
       "      <td>320012948</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999940</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>43267862</td>\n",
       "      <td>318892922</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999937</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>43267862</td>\n",
       "      <td>318313921</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999937</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>43922680</td>\n",
       "      <td>321101918</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999937</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>42597049</td>\n",
       "      <td>319044919</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999937</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>42939022</td>\n",
       "      <td>317816937</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999936</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>43829692</td>\n",
       "      <td>320351937</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999935</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>43646653</td>\n",
       "      <td>319834916</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999934</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>43922680</td>\n",
       "      <td>321147923</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999934</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>44254655</td>\n",
       "      <td>321121922</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.999934</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    RECRUIT_ID  PERSON_ID  LABEL      pred  pred_label\n",
       "0     42559662  320003954    1.0  0.999951           1\n",
       "1     42559662  320338907    1.0  0.999949           1\n",
       "2     42939022  317516901    1.0  0.999948           1\n",
       "3     43236688  317282943    1.0  0.999946           1\n",
       "4     43922680  319489936    1.0  0.999943           1\n",
       "5     43668705  320540944    1.0  0.999943           1\n",
       "6     43534698  317244952    1.0  0.999942           1\n",
       "7     44254655  320042903    1.0  0.999942           1\n",
       "8     43897745  319677903    1.0  0.999941           1\n",
       "9     42989690  317729913    1.0  0.999941           1\n",
       "10    43892655  320012948    1.0  0.999940           1\n",
       "11    43267862  318892922    1.0  0.999937           1\n",
       "12    43267862  318313921    1.0  0.999937           1\n",
       "13    43922680  321101918    1.0  0.999937           1\n",
       "14    42597049  319044919    1.0  0.999937           1\n",
       "15    42939022  317816937    1.0  0.999936           1\n",
       "16    43829692  320351937    1.0  0.999935           1\n",
       "17    43646653  319834916    1.0  0.999934           1\n",
       "18    43922680  321147923    1.0  0.999934           1\n",
       "19    44254655  321121922    1.0  0.999934           1"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_oof.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "8c8b34fc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:53.748985Z",
     "start_time": "2021-05-16T12:23:53.655661Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RECRUIT_ID</th>\n",
       "      <th>PERSON_ID</th>\n",
       "      <th>pred</th>\n",
       "      <th>LABEL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>42559662</td>\n",
       "      <td>320223900</td>\n",
       "      <td>0.999882</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>43267862</td>\n",
       "      <td>318537916</td>\n",
       "      <td>0.999880</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>43267862</td>\n",
       "      <td>319313935</td>\n",
       "      <td>0.999880</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>43809664</td>\n",
       "      <td>320148902</td>\n",
       "      <td>0.999880</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>44254655</td>\n",
       "      <td>320721906</td>\n",
       "      <td>0.999880</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   RECRUIT_ID  PERSON_ID      pred  LABEL\n",
       "0    42559662  320223900  0.999882      1\n",
       "1    43267862  318537916  0.999880      1\n",
       "2    43267862  319313935  0.999880      1\n",
       "3    43809664  320148902  0.999880      1\n",
       "4    44254655  320721906  0.999880      1"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prediction.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "03859064",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-16T12:23:54.131811Z",
     "start_time": "2021-05-16T12:23:53.751164Z"
    }
   },
   "outputs": [],
   "source": [
    "os.makedirs('sub', exist_ok=True)\n",
    "prediction[['RECRUIT_ID', 'PERSON_ID', 'LABEL']].to_csv(f'sub/{f1}.csv',\n",
    "                                                        index=False)\n",
    "prediction[['RECRUIT_ID', 'PERSON_ID', 'LABEL']].to_csv('sub/submission.csv',\n",
    "                                                        index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e609953f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:dm] *",
   "language": "python",
   "name": "conda-env-dm-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
